//
//  CommitOrderViewController.m
//  StandardizedProduct
//
//  Created by 宁宁 on 16/6/30.
//  Copyright © 2016年 ym. All rights reserved.
//

#import "CommitOrderViewController.h"

#import "CommitOrderAddressTableViewCell.h"//填写地址cell
#import "CommitOrderPackageTableViewCell.h"//包裹cell
#import "CommitOrderTotalTableViewCell.h"//合计cell
#import "CommitOrderFooterTotalString.h"//合计富文本

#import "CommitFooterView.h"//页脚View

@interface CommitOrderViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation CommitOrderViewController
{
    NSMutableArray *_packageArray;
    
    CommitFooterView *_footerView;
}

 static NSString *const CommitOrderAddressTableViewCellID = @"CommitOrderAddressTableViewCell";
 static NSString *const CommitOrderPackageTableViewCellID = @"CommitOrderPackageTableViewCell";
 static NSString *const CommitOrderTotalTableViewCellID = @"CommitOrderTotalTableViewCell";
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    self.tabBarController.tabBar.hidden = YES;
//    self.navigationController.navigationBar.translucent = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置导航栏
    [self setNav];
    
    
    //设置页脚
    [self setFooterView];
    
    //初始化数据源
    [self createData];
    
    
    //注册TableView
    [self setTableView];
    
}
#pragma mark === 设置导航栏 ===
- (void)setNav{
    self.title = @"我的订单";
    
    self.tabBarController.tabBar.hidden = YES;
}

#pragma mark === 设置页脚 ===
- (void)setFooterView{
    _footerView = [[CommitFooterView alloc] initWithFrame:CGRectMake(0, HEIGHT - 50, WIDTH, 50)];
    [_footerView.commit addTarget:self action:@selector(commitOrder) forControlEvents:UIControlEventTouchUpInside];
    _footerView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_footerView];
}

#pragma mark === 初始化数据源 ===
- (void)createData{
    _packageArray = [NSMutableArray array];
    [_packageArray addObject:@"1"];
}

#pragma mark === 注册TableView ===
- (void)setTableView{
    [self.tableView registerNib:[UINib nibWithNibName:@"CommitOrderAddressTableViewCell" bundle:nil] forCellReuseIdentifier:CommitOrderAddressTableViewCellID];
    [self.tableView registerNib:[UINib nibWithNibName:@"CommitOrderPackageTableViewCell" bundle:nil] forCellReuseIdentifier:CommitOrderPackageTableViewCellID];
    [self.tableView registerNib:[UINib nibWithNibName:@"CommitOrderTotalTableViewCell" bundle:nil] forCellReuseIdentifier:CommitOrderTotalTableViewCellID];
}


#pragma mark === TableViewDelegate ===
//section数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 1;
        case 1:
            return _packageArray.count;
        case 2:
            return 1;
        default:
            return 0;
    }
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            return 50;
        case 1:
            return 186;
        case 2:
            return 169;
        default:
            return 0;
    }
}
//cellForRow
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        CommitOrderAddressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommitOrderAddressTableViewCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else if (indexPath.section == 1){
        CommitOrderPackageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommitOrderPackageTableViewCellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        CommitOrderTotalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommitOrderTotalTableViewCellID];
        cell.total.attributedText = [CommitOrderFooterTotalString AttributedStringWithNum:@"2" andTotal:@"390.00"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}


#pragma mark === 提交订单 ===
- (void)commitOrder{
    NSLog(@"提交订单");
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0, 30, WIDTH, HEIGHT - 80)style:UITableViewStyleGrouped];
        _tableView.sectionHeaderHeight = 0;
        _tableView.sectionFooterHeight = 10.0;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end
